package com.geniusk.mqtt.utils;

public class MqttTopicUtil {

    // 私有构造方法，防止实例化
    private MqttTopicUtil() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }

    public static String getProductId(String topic) {
        return getPart(topic, 0);
    }

    public static String getDeviceId(String topic) {
        return getPart(topic, 1);
    }

    public static String getTopicType(String topic) {
        return getPart(topic, 2);
    }

    public static String getReply(String topic) {
        return getPart(topic, 3);
    }

    public static boolean hasReply(String topic) {
        return getReply(topic) != null;
    }

    private static String getPart(String topic, int index) {
        String[] parts = topic.split("/");
        if (parts.length > index) {
            return parts[index];
        }
        return null;
    }
}
